package com.joinlabs.action;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.joinlabs.entity.User;
import com.joinlabs.exception.CustomException;
import com.joinlabs.service.IUserService;

@Controller
@RequestMapping("/login")
@SessionAttributes(names= {"user"})//声明要操作session域中的 多个 域对象的名字
public class LoginAction {
	@Resource
	private IUserService userService;
   @RequestMapping("/checkLogin")
 public  ModelAndView checkLogin(User user,ModelMap map) {
	 System.out.println(user);
	 try {
		User successUser=userService.checkLogin(user);
		map.addAttribute("user",successUser);
		//用户主界面
		return new ModelAndView("redirect:/userinfo/index");
	} catch (CustomException e) {
		map.addAttribute("error",e.getMessage());
		return new ModelAndView("/login/login");
		
	}
	
	 
 }
}
